home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Unix / satan-1.1.1 / bin / rusers.satan < prev    next >
Text File  |  1996-04-24  |  2KB  |  81 lines

  1. #!/usr/local/bin/perl
  2. #
  3. # version 1, Mon Mar 20 18:49:25 1995, last mod by wietse
  4. #
  5.  
  6. # Query the target's rusers daemon and report which user logged in from
  7. # which host.  Try to clean up unqualified host names or host names that
  8. # are truncated.
  9.  
  10. $running_under_satan = 1;
  11.  
  12. require 'config/paths.pl';
  13. require 'perl/fix_hostname.pl';
  14. require 'perl/misc.pl';
  15. require 'perllib/getopts.pl';
  16.  
  17. #
  18. # Parse JCL.
  19. #
  20. $usage="Usage: rusers.satan target\n";
  21. &Getopts("v");
  22.  
  23. if ($#ARGV < 0) {
  24.     print STDERR $usage;
  25.     exit 1;
  26. }
  27. $target = $ARGV[0];
  28. $service = &basename($0, ".satan");
  29.  
  30. $| = 1;
  31.  
  32. #
  33. # Examine the output from the rusers client.
  34. #
  35. open (RUSERS, "$RUSERS -l $target 2>/dev/null|") 
  36.     || exit 1;
  37.  
  38. while (<RUSERS>) {
  39.     ($user, $where, $month, $day, $time, $idle, $host) = split;
  40.  
  41.     # Deal with hostname stuff in case of remote logins.
  42.     if (/\(.*\)/) {
  43.     if ($idle && !$host) {
  44.         $host = $idle;
  45.     }
  46.     # Get rid of X display numbers.
  47.     $host =~ s/:.*//;
  48.     $host =~ s/[()]//g;
  49.  
  50.     # Verify hostname if anything interesting was left.
  51.     if ($host ne "" && $host ne "localhost") {
  52.         # Canonicalize the host name.
  53.         if ($fqdn = &fix_hostname($host, $target)) {
  54.         $host = $fqdn;
  55.         $status = "a";
  56.         $severity = "l";
  57.         $trustee = "$user\@$target";
  58.         $trusted = "root\@$host";
  59.         $service_output = "$user";
  60.         $text = "login $user from $host";
  61.         &satan_print();
  62.         } else {
  63.         $status = "u";
  64.         $severity = "l";
  65.         $trustee = "$user\@$target";
  66.         $trusted = "root\@$host";
  67.         $service_output = "$user";
  68.         $text = "login $user from $host, unable to verify hostname";
  69.         &satan_print();
  70.         }
  71.     }
  72.     }
  73.     # Log this user, whether or not remote.
  74.     $status = "a";
  75.     $severity = "l";
  76.     $text = "login $user";
  77.     $service_output = "$user";
  78.     $trusted = $trustee = "";
  79.     &satan_print();
  80. }
  81.